package cate.game.play.skill.active;

import cate.game.play.base.HpCfg;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.DamageResult;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;

/**
 * 效果：随机对敌方1个目标造成480%物理伤害，若未击杀则额外造成8%目标最大生命值的伤害，若击杀目标则将溢出伤害的100%转移至随机1个敌方目标
 * 强化效果：转移伤害击杀目标仍会再转移1次，但效率为80%;
 */
public class 将近酒AH extends ActiveHandler{


	private HpCfg 血量配置;

	private double 转移比例;

	private double 二次转移;

	//血量配置=？？&转移比例=10000&二次转移=8000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量配置 = new HpCfg(args);
		转移比例 = args.getWDouble("转移比例", 0d);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		二次转移 = args.getWDouble("二次转移", 0d);
	}

	@Override
	public void afterSingleEffect(SkillActionCtx action, SkillEffect effect, Fighter target) {
		if (!target.isDead()) {
			if (!血量配置.isEmpty()) {
				target.attr.buffHurt(action, skill.owner, 血量配置.settle(skill.owner, target));
			}
		} else {
			double overDamage = action.getStat().getTotalOverFlowSkillDamage(skill.owner.getPid(), target.getPid());
			DamageResult damageResult = transferDamage(action, overDamage * 转移比例);
			if (二次转移 > 0 && damageResult != null && damageResult.overFlowDamage > 0) {
				transferDamage(action, damageResult.overFlowDamage * 二次转移);
			}
		}
	}

	private DamageResult transferDamage(SkillActionCtx action,double damage){
		Fighter transferTarget = TargetSelector.findOne(skill.owner, action.getTeamVs(), new TargetFilterParam());
		if (transferTarget != null) {
			return transferTarget.attr.buffHurt(action, skill.owner, damage);
		}else {
			return null;
		}
	}




}
